package com.qzsoft.zhjd.laboratory.modules.marshallStabilityNew.entity;

import lombok.AllArgsConstructor;

/**
 * 指定设备 类型的结果解析
 */
@AllArgsConstructor
public enum SpecifiedDeviceResolve {

    /**
     * 马歇尔
     */
    DEV_MARSHALL {
        @Override
        public <R1 extends BJSSXProtocolParser.BaseRealtimeData, R2 extends BJSSXProtocolParser.BaseResultData> BJSSXProtocolParser<R1, R2> resolve(byte[] frame) {
            // 先校验并截取出对应数据内容！
            BJSSXProtocolParser<BJSSXProtocolParser.MarshallStabilityRealtimeData, BJSSXProtocolParser.MarshallStabilityResultData> parseFrame = BJSSXProtocolParser.parseFrame(frame, false);

            byte[] dataBytes = parseFrame.getRawData(); // 数据内容

            // 数据类型确定是实时数据还是结果数据[0x01 或 0x02]
            if (parseFrame.getCommand() == BJSSXProtocolParser.REALTIME_HEX) {
                // TODO：实时数据
                BJSSXProtocolParser.BaseRealtimeData<BJSSXProtocolParser.MarshallStabilityRealtimeData> realtimeData = BJSSXProtocolParser.BaseRealtimeData.parseRealtime(dataBytes, BJSSXProtocolParser.DEV_MARSHALL);
                if (realtimeData instanceof BJSSXProtocolParser.MarshallStabilityRealtimeData) {
                    parseFrame.setRealtimeData((BJSSXProtocolParser.MarshallStabilityRealtimeData) realtimeData);
                }
            } else if (parseFrame.getCommand() == BJSSXProtocolParser.RESULT_HEX) {
                // TODO：结果数据
                BJSSXProtocolParser.BaseResultData resultData = BJSSXProtocolParser.BaseResultData.parseResult(dataBytes);
                if (resultData instanceof BJSSXProtocolParser.MarshallStabilityResultData) {
                    parseFrame.setResultData((BJSSXProtocolParser.MarshallStabilityResultData) resultData);
                }
            }
            return (BJSSXProtocolParser<R1, R2>) parseFrame;
        }
    },

    /**
     * 针入度
     */
    DEV_PENETRATION {
        @Override
        public <R1 extends BJSSXProtocolParser.BaseRealtimeData, R2 extends BJSSXProtocolParser.BaseResultData> BJSSXProtocolParser<R1, R2> resolve(byte[] frame) {
            // 先校验并截取出对应数据内容！
            BJSSXProtocolParser<BJSSXProtocolParser.PenetrationRealtimeData, BJSSXProtocolParser.PenetrationResultData> parseFrame = BJSSXProtocolParser.parseFrame(frame, false);

            byte[] dataBytes = parseFrame.getRawData(); // 数据内容

            // 数据类型确定是实时数据还是结果数据[0x01 或 0x02]
            if (parseFrame.getCommand() == BJSSXProtocolParser.REALTIME_HEX) {
                // TODO：实时数据
                BJSSXProtocolParser.BaseRealtimeData realtimeData = BJSSXProtocolParser.BaseRealtimeData.parseRealtime(dataBytes, BJSSXProtocolParser.DEV_PENETRATION);
                if (realtimeData instanceof BJSSXProtocolParser.PenetrationRealtimeData) {
                    parseFrame.setRealtimeData((BJSSXProtocolParser.PenetrationRealtimeData) realtimeData);
                }
            } else if (parseFrame.getCommand() == BJSSXProtocolParser.RESULT_HEX) {
                // TODO：结果数据
                BJSSXProtocolParser.BaseResultData resultData = BJSSXProtocolParser.BaseResultData.parseResult(dataBytes);
                if (resultData instanceof BJSSXProtocolParser.PenetrationResultData) {
                    parseFrame.setResultData((BJSSXProtocolParser.PenetrationResultData) resultData);
                }
            }
            return (BJSSXProtocolParser<R1, R2>) parseFrame;
        }
    },

    /**
     * 延度仪
     */
    DEV_DUCTILITY {
        @Override
        public <R1 extends BJSSXProtocolParser.BaseRealtimeData, R2 extends BJSSXProtocolParser.BaseResultData> BJSSXProtocolParser<R1, R2> resolve(byte[] frame) {
            // 先校验并截取出对应数据内容！
            BJSSXProtocolParser<BJSSXProtocolParser.DuctilityRealtimeData, BJSSXProtocolParser.DuctilityResultData> parseFrame = BJSSXProtocolParser.parseFrame(frame, false);

            byte[] dataBytes = parseFrame.getRawData(); // 数据内容

            // 数据类型确定是实时数据还是结果数据[0x01 或 0x02]
            if (parseFrame.getCommand() == BJSSXProtocolParser.REALTIME_HEX) {
                // TODO：实时数据
                BJSSXProtocolParser.BaseRealtimeData realtimeData = BJSSXProtocolParser.BaseRealtimeData.parseRealtime(dataBytes, BJSSXProtocolParser.DEV_DUCTILITY);
                if (realtimeData instanceof BJSSXProtocolParser.DuctilityRealtimeData) {
                    parseFrame.setRealtimeData((BJSSXProtocolParser.DuctilityRealtimeData) realtimeData);
                }
            } else if (parseFrame.getCommand() == BJSSXProtocolParser.RESULT_HEX) {
                // TODO：结果数据
                BJSSXProtocolParser.BaseResultData resultData = BJSSXProtocolParser.BaseResultData.parseResult(dataBytes);
                if (resultData instanceof BJSSXProtocolParser.DuctilityResultData) {
                    parseFrame.setResultData((BJSSXProtocolParser.DuctilityResultData) resultData);
                }
            }
            return (BJSSXProtocolParser<R1, R2>) parseFrame;
        }
    },

    /**
     * 软化点
     */
    DEV_SOFTENING {
        @Override
        public <R1 extends BJSSXProtocolParser.BaseRealtimeData, R2 extends BJSSXProtocolParser.BaseResultData> BJSSXProtocolParser<R1, R2> resolve(byte[] frame) {
            // 先校验并截取出对应数据内容！
            BJSSXProtocolParser<BJSSXProtocolParser.SofteningPointRealtimeData, BJSSXProtocolParser.SofteningPointResultData> parseFrame = BJSSXProtocolParser.parseFrame(frame, false);

            byte[] dataBytes = parseFrame.getRawData(); // 数据内容

            // 数据类型确定是实时数据还是结果数据[0x01 或 0x02]
            if (parseFrame.getCommand() == BJSSXProtocolParser.REALTIME_HEX) {
                // TODO：实时数据
                BJSSXProtocolParser.BaseRealtimeData realtimeData = BJSSXProtocolParser.BaseRealtimeData.parseRealtime(dataBytes, BJSSXProtocolParser.DEV_SOFTENING);
                if (realtimeData instanceof BJSSXProtocolParser.SofteningPointRealtimeData) {
                    parseFrame.setRealtimeData((BJSSXProtocolParser.SofteningPointRealtimeData) realtimeData);
                }
            } else if (parseFrame.getCommand() == BJSSXProtocolParser.RESULT_HEX) {
                // TODO：结果数据
                BJSSXProtocolParser.BaseResultData resultData = BJSSXProtocolParser.BaseResultData.parseResult(dataBytes);
                if (resultData instanceof BJSSXProtocolParser.SofteningPointResultData) {
                    parseFrame.setResultData((BJSSXProtocolParser.SofteningPointResultData) resultData);
                }
            }
            return (BJSSXProtocolParser<R1, R2>) parseFrame;
        }
    };

    /**
     * 解析数据
     *
     * @param frame 数据帧结构！
     * @return {@link BJSSXProtocolParser.BaseRealtimeData }
     */
    public abstract <R1 extends BJSSXProtocolParser.BaseRealtimeData, R2 extends BJSSXProtocolParser.BaseResultData> BJSSXProtocolParser<R1, R2> resolve(byte[] frame); // 抽象方法

}
